<template>
  <div class="process-status">
    <!-- 水平步骤条（PC和移动端都展示） -->
    <div class="process-steps">
      <div 
        v-for="(step, index) in steps" 
        :key="index"
        class="step-item"
        :class="[
          { 'is-completed': isCompleted(index) },
          { 'is-current': isCurrent(index) },
          { 'is-error': isError(index) }
        ]"
      >
        <!-- 步骤节点 -->
        <div class="step-node">
          <div class="step-icon">
            <i 
              v-if="isCompleted(index) && !isError(index)" 
              class="fas fa-check step-icon-inner"
            ></i>
            <i 
              v-else-if="isError(index)" 
              class="fas fa-times step-icon-inner"
            ></i>
            <span v-else class="step-number">{{ index + 1 }}</span>
          </div>
          
          <!-- 连接线 -->
          <div 
            v-if="index < steps.length - 1" 
            class="step-line"
            :class="{ 'is-active': isCompleted(index) }"
          ></div>
        </div>
        
        <!-- 步骤文本 -->
        <div class="step-content">
          <div class="step-title">{{ step.title }}</div>
          <div v-if="step.description" class="step-description">{{ step.description }}</div>
          <div v-if="step.time" class="step-time">{{ step.time }}</div>
        </div>
      </div>
    </div>
    
    <!-- 时间线视图 (仅在PC端有足够宽度时展示详情) -->
    <div v-if="showTimeline && !isMobileView" class="process-timeline">
      <div 
        v-for="(step, index) in steps" 
        :key="index"
        class="timeline-item"
        :class="[
          { 'is-completed': isCompleted(index) },
          { 'is-current': isCurrent(index) },
          { 'is-error': isError(index) }
        ]"
      >
        <div class="timeline-node"></div>
        <div class="timeline-content">
          <div class="timeline-title">
            <span class="timeline-step">{{ step.title }}</span>
            <span v-if="step.time" class="timeline-time">{{ step.time }}</span>
          </div>
          <div v-if="step.description" class="timeline-description">{{ step.description }}</div>
          <div v-if="step.remark" class="timeline-remark">{{ step.remark }}</div>
          
          <!-- 操作人信息 -->
          <div v-if="step.operator" class="timeline-operator">
            <span class="operator-avatar">
              <img v-if="step.operatorAvatar" :src="step.operatorAvatar" alt="头像">
              <i v-else class="fas fa-user"></i>
            </span>
            <span class="operator-name">{{ step.operator }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ProcessStatus',
  props: {
    steps: {
      type: Array,
      required: true,
      validator: (value) => Array.isArray(value) && value.every(step => 
        typeof step === 'object' && 'title' in step
      )
    },
    currentStep: {
      type: Number,
      default: 0
    },
    showTimeline: {
      type: Boolean,
      default: true
    },
    errorSteps: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      isMobileView: window.innerWidth < 768
    }
  },
  mounted() {
    window.addEventListener('resize', this.checkMobileView)
  },
  beforeUnmount() {
    window.removeEventListener('resize', this.checkMobileView)
  },
  methods: {
    // 检查是否处于移动视图
    checkMobileView() {
      this.isMobileView = window.innerWidth < 768
    },
    
    // 检查步骤是否完成
    isCompleted(index) {
      return index < this.currentStep
    },
    
    // 检查是否为当前步骤
    isCurrent(index) {
      return index === this.currentStep
    },
    
    // 检查步骤是否出错
    isError(index) {
      return this.errorSteps.includes(index)
    }
  }
}
</script>

<style scoped>
.process-status {
  margin: 32px 0;
}

/* 水平步骤条样式 */
.process-steps {
  display: flex;
  width: 100%;
  margin-bottom: 40px;
}

.step-item {
  flex: 1;
  position: relative;
  padding: 0 8px;
}

.step-node {
  display: flex;
  align-items: center;
  position: relative;
  margin-bottom: 16px;
}

.step-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background-color: var(--background-grey);
  border: 2px solid var(--divider);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 2;
  transition: all var(--transition-normal);
  box-shadow: var(--shadow-sm);
}

.step-icon-inner, .step-number {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
}

.step-line {
  height: 3px;
  flex: 1;
  background-color: var(--divider);
  margin: 0 4px;
  position: relative;
  z-index: 1;
  transition: background-color var(--transition-normal);
}

.step-content {
  padding-right: 16px;
}

.step-title {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.step-description {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

.step-time {
  font-size: 12px;
  color: var(--text-secondary);
}

/* 已完成步骤样式 */
.step-item.is-completed .step-icon {
  background-color: var(--success-bg);
  border-color: var(--success);
  box-shadow: 0 0 0 4px var(--success-bg);
}

.step-item.is-completed .step-icon-inner {
  color: var(--success);
}

.step-line.is-active {
  background-color: var(--success);
}

/* 当前步骤样式 */
.step-item.is-current .step-icon {
  background-color: var(--primary-blue);
  border-color: var(--primary-blue);
  box-shadow: 0 0 0 4px var(--primary-blue-bg);
  transform: scale(1.1);
}

.step-item.is-current .step-icon-inner,
.step-item.is-current .step-number {
  color: white;
  font-weight: 600;
}

.step-item.is-current .step-title {
  color: var(--primary-blue);
  font-weight: 600;
}

/* 错误步骤样式 */
.step-item.is-error .step-icon {
  background-color: var(--error-bg);
  border-color: var(--error);
  box-shadow: 0 0 0 4px var(--error-bg);
}

.step-item.is-error .step-icon-inner {
  color: var(--error);
}

.step-item.is-error .step-title {
  color: var(--error);
}

/* 时间线视图样式 */
.process-timeline {
  margin-top: 40px;
  border-left: 2px solid var(--divider);
  padding-left: 24px;
}

.timeline-item {
  position: relative;
  padding-bottom: 32px;
}

.timeline-item:last-child {
  padding-bottom: 0;
}

.timeline-node {
  position: absolute;
  left: -30px;
  top: 0;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background-color: var(--divider);
  border: 3px solid var(--background-white);
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-normal);
}

.timeline-content {
  padding-left: 12px;
  background-color: var(--background-white);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-fast);
}

.timeline-content:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.timeline-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.timeline-step {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.timeline-time {
  font-size: 13px;
  color: var(--text-secondary);
  background-color: var(--grey-100);
  padding: 3px 8px;
  border-radius: 12px;
}

.timeline-description {
  font-size: 14px;
  color: var(--text-primary);
  margin-bottom: 12px;
}

.timeline-remark {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 12px;
  background-color: var(--grey-100);
  padding: 12px;
  border-radius: var(--radius-md);
  border-left: 3px solid var(--grey-300);
}

.timeline-operator {
  display: flex;
  align-items: center;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--divider);
}

.operator-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background-color: var(--grey-200);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 8px;
  overflow: hidden;
}

.operator-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.operator-avatar i {
  font-size: 12px;
  color: var(--text-secondary);
}

.operator-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

/* 已完成的时间线样式 */
.timeline-item.is-completed .timeline-node {
  background-color: var(--success);
  border-color: var(--success-bg);
  box-shadow: 0 0 0 3px var(--success-bg);
}

.timeline-item.is-completed .timeline-content {
  border-left: 3px solid var(--success);
}

/* 当前步骤的时间线样式 */
.timeline-item.is-current .timeline-node {
  background-color: var(--primary-blue);
  border-color: var(--primary-blue-bg);
  box-shadow: 0 0 0 4px var(--primary-blue-bg);
  width: 20px;
  height: 20px;
  left: -32px;
}

.timeline-item.is-current .timeline-step {
  color: var(--primary-blue);
}

.timeline-item.is-current .timeline-content {
  background-color: var(--primary-blue-bg);
  border-left: 3px solid var(--primary-blue);
}

/* 错误步骤的时间线样式 */
.timeline-item.is-error .timeline-node {
  background-color: var(--error);
  border-color: var(--error-bg);
  box-shadow: 0 0 0 3px var(--error-bg);
}

.timeline-item.is-error .timeline-step {
  color: var(--error);
}

.timeline-item.is-error .timeline-content {
  background-color: var(--error-bg);
  border-left: 3px solid var(--error);
}

/* 移动端适配 */
@media (max-width: 768px) {
  .process-steps {
    overflow-x: auto;
    padding-bottom: 8px;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 24px;
  }
  
  .step-item {
    flex: none;
    min-width: 120px;
  }
  
  .step-content {
    padding-right: 16px;
  }
  
  .process-timeline {
    margin-top: 32px;
    padding-left: 20px;
  }
  
  .timeline-content {
    padding: 12px;
  }
  
  .timeline-title {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .timeline-time {
    margin-top: 8px;
  }
}
</style> 